﻿using System.Web.Mvc;

using SCB.Common;
using SCB.Presentation.Models;
using SCB.Presentation.Helpers;

namespace SCB.Presentation.Controllers
{
    public class CategoryController : Controller
    {
        public ActionResult Display(int id, string keyword = "")
        {
            var category = CategoryService.GetCategoryParentId(id);

            var models = new UICategoriesModels
                             {
                                 CategoryTitle = category.Name,
                                 Categories = CategoryService.LeftPanelData,
                                 Subcategories = CategoryService.GetSubcategoris(id)
                             };
            if (!string.IsNullOrEmpty(keyword))
                SearchHistoryService.UpdateSearchHistory(new DTOSearchHistory() { Text = category.Name, Link = Utilities.GetCategoryDetailView(id, category.Name) });
            if (category.ParentId == 0)
            {
                return View("CategoriesList", models);
            }
            else
            {
                return View("CategoriesDetails", models);
            }
        }
    }
}
